package com.mall.db.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mall.db.mapper.CmsSubjectProductRelationMapper;
import com.mall.pojo.CmsSubjectProductRelation;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class CmsSubjectProductRelationApiAmpl implements CmsSubjectProductRelationApi {
    @Autowired
    private CmsSubjectProductRelationMapper cmsSubjectProductRelationMapper;

    //创建商品(八接口之一)
    @Override
    public void create(List<CmsSubjectProductRelation> subjectProductRelationList) {
        if (subjectProductRelationList != null) {
            for (CmsSubjectProductRelation cmsSubjectProductRelation : subjectProductRelationList) {
                cmsSubjectProductRelationMapper.insert(cmsSubjectProductRelation);
            }
        }
    }

    //更新商品 更新八张表之一
    @Override
    public void update(List<CmsSubjectProductRelation> subjectProductRelationList) {
        if (subjectProductRelationList != null) {
            for (CmsSubjectProductRelation cmsSubjectProductRelation : subjectProductRelationList) {
                cmsSubjectProductRelationMapper.updateById(cmsSubjectProductRelation);
            }
        }
    }

    @Override
    public List<CmsSubjectProductRelation> selectById(Integer id) {
        LambdaQueryWrapper<CmsSubjectProductRelation> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CmsSubjectProductRelation::getProductId, id);
        return cmsSubjectProductRelationMapper.selectList(wrapper);
    }
}
